layui.use(['element', 'table', 'form', 'layer', 'laytpl'], function () {
    const $ = layui.$,
        element = layui.element,
        table = layui.table,
        form = layui.form,
        layer = layui.layer,
        laytpl = layui.laytpl;

    // 初始化门岗数据映射
    let gateMap = {};

    // 加载门岗数据
    async function loadGates() {
        try {
            const res = await $.ajax({
                url: 'http://localhost:8080/gate',
                method: 'GET'
            });

            if (res.code === 0 && Array.isArray(res.data)) {
                res.data.forEach(item => {
                    gateMap[item.id] = item.gate;
                });
                return res.data;
            } else {
                throw new Error('门岗数据格式错误');
            }
        } catch (error) {
            console.error('门岗数据加载失败:', error);
            layer.msg('门岗数据加载失败', {icon: 2});
            return [];
        }
    }

    // 初始化单位数据映射
    let unitMap = {};

    // 加载单位数据
    async function loadUnits() {
        try {
            const res = await $.ajax({
                url: 'http://localhost:8080/unit',
                method: 'GET'
            });

            if (res.code === "200" && Array.isArray(res.data)) {
                res.data.forEach(item => {
                    unitMap[item.id] = item.unitName;
                });
                return res.data;
            } else {
                throw new Error('单位数据格式错误');
            }
        } catch (error) {
            console.error('单位数据加载失败:', error);
            layer.msg('单位数据加载失败', {icon: 2});
            return [];
        }
    }

    // 材料管理表格
    const materialTable = table.render({
        elem: '#materialTable',
        url: 'http://localhost:8080/material',
        cols: [[{
            field: 'id',
            title: 'ID',
            width: 80
        }, {
            field: 'materialType',
            title: '材料类型',
            width: 150
        }, {
            field: 'density',
            title: '密度',
            width: 120,
            templet: d => (d.density || 0).toFixed(2)
        }, {
            title: '操作',
            width: 200,
            toolbar: '#infoActionTpl'
        }]],
        page: true,
        limit: 10,
        response: {statusCode: 0},
        request: {
            pageName: 'page',
            limitName: 'size'
        },
        done: function(res) {
            if (!res || !Array.isArray(res.data)) {
                layer.msg('数据格式异常', {icon: 2});
            }
        }
    });

    // 车辆尺寸管理表格
    const truckSizeTable = table.render({
        elem: '#truckSizeTable',
        url: 'http://localhost:8080/truck-size/all',
        cols: [[{
            field: 'id',
            title: 'ID',
            width: 80
        }, {
            field: 'truckType',
            title: '车辆类型',
            width: 150
        }, {
            field: 'height',
            title: '高度',
            width: 120,
            templet: d => (d.height || 0).toFixed(2)
        }, {
            field: 'width',
            title: '宽度',
            width: 120,
            templet: d => (d.width || 0).toFixed(2)
        }, {
            field: 'length',
            title: '长度',
            width: 120,
            templet: d => (d.length || 0).toFixed(2)
        }, {
            title: '操作',
            width: 200,
            toolbar: '#infoActionTpl'
        }]],
        page: true,
        limit: 10,
        response: {statusCode: 0},
        request: {
            pageName: 'page',
            limitName: 'size'
        },
        done: function(res) {
            if (!res || !Array.isArray(res.data)) {
                layer.msg('数据格式异常', {icon: 2});
            }
        }
    });

    // 车辆信息管理表格
    const truckUnitTable = table.render({
        elem: '#truckUnitTable',
        url: 'http://localhost:8080/truck-unit/all',
        cols: [[{
            field: 'id',
            title: 'ID',
            width: 80
        }, {
            field: 'plate',
            title: '车牌号',
            width: 150
        }, {
            field: 'truckType',
            title: '车辆类型',
            width: 150
        }, {
            field: 'belonging',
            title: '所属单位',
            width: 180
        }, {
            title: '操作',
            width: 200,
            toolbar: '#infoActionTpl'
        }]],
        page: true,
        limit: 10,
        response: {statusCode: 0},
        request: {
            pageName: 'page',
            limitName: 'size'
        },
        done: function(res) {
            if (!res || !Array.isArray(res.data)) {
                layer.msg('数据格式异常', {icon: 2});
            }
        }
    });

    // 单位管理表格
    const unitTable = table.render({
        elem: '#unitTable',
        url: 'http://localhost:8080/unit/all',
        cols: [[{
            field: 'id',
            title: 'ID',
            width: 80
        }, {
            field: 'unitName',
            title: '单位名称',
            width: 200
        }, {
            title: '操作',
            width: 200,
            toolbar: '#infoActionTpl'
        }]],
        page: true,
        limit: 10,
        response: {statusCode: 0},
        request: {
            pageName: 'page',
            limitName: 'size'
        },
        done: function(res) {
            if (!res || !Array.isArray(res.data)) {
                layer.msg('数据格式异常', {icon: 2});
            }
        }
    });

    // 门岗管理表格
    const gateTable = table.render({
        elem: '#gateTable',
        url: 'http://localhost:8080/gate/all',
        cols: [[{
            field: 'id',
            title: 'ID',
        }, {
            field: 'gate',
            title: '门岗名称',
            width: 200
        }, {
            title: '操作',
            width: 200,
            toolbar: '#infoActionTpl'
        }]],
        page: true,
        limit: 10,
        response: {statusCode: 0},
        request: {
            pageName: 'page',
            limitName: 'size'
        },
        done: function(res) {
            if (!res || !Array.isArray(res.data)) {
                layer.msg('数据格式异常', {icon: 2});
            }
        }
    });

    // 更新当前时间
    function updateCurrentTime() {
        const now = moment().format('YYYY年MM月DD日 HH:mm:ss');
        $('#currentTime').text(now);
        $('#currentTimeMobile').text(now);
    }

    setInterval(updateCurrentTime, 1000);
    updateCurrentTime(); // 初始化一次

    // 页面加载完成后执行
    $(document).ready(async function () {
        // 先加载所有需要的数据
        const [units, gates] = await Promise.all([
            loadUnits(),
            loadGates()
        ]);

        const username = sessionStorage.getItem('username');
        const unitId = sessionStorage.getItem('unitId');

        if (!username || !unitId) {
            layer.msg('请先登录', {icon: 2});
            setTimeout(() => window.location.href = '/login.html', 1500);
        } else {
            $('#usernameDisplay').text(username);
            $('#usernameDisplayMobile').text(username);
            initNav();
            element.init();
        }
    });

    // 初始化导航状态
    function initNav() {
        $('.layui-nav-item[data-tab="material"]')
            .addClass('layui-this')
            .siblings().removeClass('layui-this');
        element.render('nav');
    }

    // 导航栏切换事件
    $(document).on('click', '.layui-nav-item', function () {
        const $navItem = $(this);
        const tabId = $navItem.data('tab');
        if (!tabId) return;

        // 更新导航状态
        $navItem.addClass('layui-this').siblings().removeClass('layui-this');

        // 切换标签页
        setTimeout(() => {
            element.render('nav');
            element.tabChange('infoTabs', tabId);
        }, 100);
    });

    // 监听窗口变化重新渲染
    $(window).on('resize', function () {
        element.render('tab');
        element.render('nav');
    });

    // 表单验证规则
    form.verify({
        materialType: function(value) {
            if (!value) {
                return '材料类型不能为空';
            }
            if (value.length < 2) {
                return '材料类型至少需要2个字符';
            }
        },
        gateName: function(value) {
            if (!value) {
                return '门岗名称不能为空';
            }
            if (value.length < 2) {
                return '门岗名称至少需要2个字符';
            }
        },
        unitName: function(value) {
            if (!value) {
                return '单位名称不能为空';
            }
            if (value.length < 2) {
                return '单位名称至少需要2个字符';
            }
        },
        plate: function(value) {
            if (value && !/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼]{1}[A-HJ-NP-Z]{1}[A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]{0,1}$/.test(value)) {
                return '请输入正确的车牌号格式';
            }
        }
    });

    // 材料管理操作
    table.on('tool(materialTable)', function(obj) {
        const data = obj.data;
        if (obj.event === 'edit') {
            editMaterial(data);
        } else if (obj.event === 'delete') {
            deleteMaterial(data);
        }
    });

    // 车辆尺寸管理操作
    table.on('tool(truckSizeTable)', function(obj) {
        const data = obj.data;
        if (obj.event === 'edit') {
            editTruckSize(data);
        } else if (obj.event === 'delete') {
            deleteTruckSize(data);
        }
    });

    // 车辆信息管理操作
    table.on('tool(truckUnitTable)', function(obj) {
        const data = obj.data;
        if (obj.event === 'edit') {
            editTruckUnit(data);
        } else if (obj.event === 'delete') {
            deleteTruckUnit(data);
        }
    });

    // 单位管理操作
    table.on('tool(unitTable)', function(obj) {
        const data = obj.data;
        if (obj.event === 'edit') {
            editUnit(data);
        } else if (obj.event === 'delete') {
            deleteUnit(data);
        }
    });

    // 门岗管理操作
    table.on('tool(gateTable)', function(obj) {
        const data = obj.data;
        if (obj.event === 'edit') {
            editGate(data);
        } else if (obj.event === 'delete') {
            deleteGate(data);
        }
    });

    // 添加材料功能
    $('#addMaterialBtn').click(() => addMaterial());

    // 添加材料
    function addMaterial() {
        layer.open({
            type: 1,
            title: '添加材料',
            area: ['500px', '400px'],
            content: laytpl($('#addMaterialTpl').html()).render(),
            success: function(layero) {
                form.render(); // 渲染表单元素

                // 绑定提交事件
                form.on('submit(addMaterialForm)', function(formData) {
                    submitMaterial(formData, false);
                    return false;
                });
            }
        });
    }

    // 编辑材料
    function editMaterial(data) {
        layer.open({
            type: 1,
            title: '编辑材料',
            area: ['500px', '400px'],
            content: laytpl($('#addMaterialTpl').html()).render({
                id: data.id,
                materialType: data.materialType,
                density: data.density
            }),
            success: function(layero) {
                // 填充表单
                form.val("addMaterialForm", {
                    id: data.id,
                    materialType: data.materialType,
                    density: data.density
                });

                form.render(); // 重新渲染表单

                // 绑定提交事件
                form.on('submit(addMaterialForm)', function(formData) {
                    submitMaterial(formData, true, data);
                    return false;
                });
            }
        });
    }

    // 提交材料
    function submitMaterial(formData, isEdit, originalData) {
        const fields = formData.field;

        // 如果是编辑，保留原始ID
        if (isEdit) {
            fields.id = originalData.id;
        }

        // 数据格式转换
        fields.density = parseFloat(fields.density) || 0;

        $.ajax({
            url: isEdit ? 'http://59.110.144.74:8080/material/update' : 'http://59.110.144.74:8080/material/add',
            method: isEdit ? 'PUT' : 'POST',
            contentType: 'application/json',
            data: JSON.stringify(fields),
            success: function(res) {
                if (res.success !== undefined && res.success) {
                    layer.msg(isEdit ? '更新成功' : '添加成功', {icon: 1});
                    materialTable.reload();
                    layer.closeAll();
                } else {
                    layer.msg(isEdit ? '更新失败' : '添加失败', {icon: 2});
                }
            },
            error: function(xhr) {
                console.error(isEdit ? '更新材料失败:' : '添加材料失败:', xhr);
                layer.msg(`服务器错误: ${xhr.statusText}`, {icon: 2});
            }
        });
    }

    // 删除材料
    function deleteMaterial(data) {
        layer.confirm('确定删除该材料？', {
            icon: 3,
            title: '确认删除'
        }, function(index) {
            $.ajax({
                url: `http://localhost:8080/material/delete/${data.id}`,
                type: 'DELETE',
                success: function(res) {
                    if (res.success !== undefined && res.success) {
                        layer.msg('删除成功', {icon: 1});
                        materialTable.reload();
                    } else {
                        layer.msg('删除失败', {icon: 2});
                    }
                },
                error: function(xhr) {
                    console.error('删除材料失败:', xhr);
                    layer.msg(`删除失败: ${xhr.statusText}`, {icon: 2});
                }
            });
            layer.close(index);
        });
    }

    // 添加车辆尺寸功能
    $('#addTruckSizeBtn').click(() => addTruckSize());

    // 添加车辆尺寸
    function addTruckSize() {
        layer.open({
            type: 1,
            title: '添加车辆尺寸',
            area: ['500px', '450px'],
            content: laytpl($('#addTruckSizeTpl').html()).render(),
            success: function(layero) {
                form.render(); // 渲染表单元素

                // 绑定提交事件
                form.on('submit(addTruckSizeForm)', function(formData) {
                    submitTruckSize(formData, false);
                    return false;
                });
            }
        });
    }

    // 编辑车辆尺寸
    function editTruckSize(data) {
        layer.open({
            type: 1,
            title: '编辑车辆尺寸',
            area: ['500px', '450px'],
            content: laytpl($('#addTruckSizeTpl').html()).render({
                id: data.id,
                truckType: data.truckType,
                height: data.height,
                width: data.width,
                length: data.length
            }),
            success: function(layero) {
                // 填充表单
                form.val("addTruckSizeForm", {
                    id: data.id,
                    truckType: data.truckType,
                    height: data.height,
                    width: data.width,
                    length: data.length
                });

                form.render(); // 重新渲染表单

                // 绑定提交事件
                form.on('submit(addTruckSizeForm)', function(formData) {
                    submitTruckSize(formData, true, data);
                    return false;
                });
            }
        });
    }

    // 提交车辆尺寸
    function submitTruckSize(formData, isEdit, originalData) {
        const fields = formData.field;

        // 如果是编辑，保留原始ID
        if (isEdit) {
            fields.id = originalData.id;
        }

        // 数据格式转换
        fields.height = parseFloat(fields.height) || 0;
        fields.width = parseFloat(fields.width) || 0;
        fields.length = parseFloat(fields.length) || 0;

        $.ajax({
            url: isEdit ? 'http://59.110.144.74:8080/truck-size/update' : 'http://59.110.144.74:8080/truck-size/add',
            method: isEdit ? 'PUT' : 'POST',
            contentType: 'application/json',
            data: JSON.stringify(fields),
            success: function(res) {
                if (res) {
                    layer.msg(isEdit ? '更新成功' : '添加成功', {icon: 1});
                    truckSizeTable.reload();
                    layer.closeAll();
                } else {
                    layer.msg(isEdit ? '更新失败' : '添加失败', {icon: 2});
                }
            },
            error: function(xhr) {
                console.error(isEdit ? '更新失败:' : '添加失败:', xhr);
                layer.msg(`操作失败: ${xhr.statusText}`, {icon: 2});
            }
        });
    }

    // 删除车辆尺寸
    function deleteTruckSize(data) {
        layer.confirm('确定删除该车辆尺寸？', {
            icon: 3,
            title: '确认删除'
        }, function(index) {
            $.ajax({
                url: `http://localhost:8080/truck-size/delete/${data.id}`,
                type: 'DELETE',
                success: function(res) {
                    if (res) {
                        layer.msg('删除成功', {icon: 1});
                        truckSizeTable.reload();
                    } else {
                        layer.msg('删除失败', {icon: 2});
                    }
                },
                error: function(xhr) {
                    console.error('删除失败:', xhr);
                    layer.msg(`删除失败: ${xhr.statusText}`, {icon: 2});
                }
            });
            layer.close(index);
        });
    }

    // 添加车辆信息功能
    $('#addTruckUnitBtn').click(() => addTruckUnit());

    // 添加车辆信息
    function addTruckUnit() {
        loadUnits().then(units => {
            layer.open({
                type: 1,
                title: '添加车辆信息',
                area: ['500px', '400px'],
                content: laytpl($('#addTruckUnitTpl').html()).render({ units: units }),
                success: function(layero) {
                    form.render('select'); // 重新渲染select

                    // 绑定提交事件
                    form.on('submit(addTruckUnitForm)', function(formData) {
                        submitTruckUnit(formData, false);
                        return false;
                    });
                }
            });
        }).catch(err => {
            layer.msg('单位数据加载失败', { icon: 2 });
        });
    }

    // 编辑车辆信息
    function editTruckUnit(data) {
        loadUnits().then(units => {
            layer.open({
                type: 1,
                title: '编辑车辆信息',
                area: ['500px', '400px'],
                content: laytpl($('#addTruckUnitTpl').html()).render({
                    d: data,
                    units: units
                }),
                success: function(layero) {
                    // 填充表单
                    form.val("addTruckUnitForm", {
                        id: data.id,
                        plate: data.plate,
                        truckType: data.truckType,
                        belonging: data.belonging
                    });

                    form.render(); // 重新渲染表单

                    // 绑定提交事件
                    form.on('submit(addTruckUnitForm)', function(formData) {
                        submitTruckUnit(formData, true, data);
                        return false;
                    });
                }
            });
        }).catch(err => {
            layer.msg('单位数据加载失败', { icon: 2 });
        });
    }

    // 提交车辆信息
    function submitTruckUnit(formData, isEdit, originalData) {
        const fields = formData.field;

        // 如果是编辑，保留原始ID
        if (isEdit) {
            fields.id = originalData.id;
        }

        // 数据格式转换
        fields.plate = fields.plate || '';
        fields.truckType = fields.truckType || '';
        fields.belonging = fields.belonging || '';

        $.ajax({
            url: isEdit ? 'http://59.110.144.74:8080/truck-unit/update' : 'http://59.110.144.74:8080/truck-unit/add',
            method: isEdit ? 'PUT' : 'POST',
            contentType: 'application/json',
            data: JSON.stringify(fields),
            success: function(res) {
                if (res) {
                    layer.msg(isEdit ? '更新成功' : '添加成功', {icon: 1});
                    truckUnitTable.reload();
                    layer.closeAll();
                } else {
                    layer.msg(isEdit ? '更新失败' : '添加失败', {icon: 2});
                }
            },
            error: function(xhr) {
                console.error(isEdit ? '更新失败:' : '添加失败:', xhr);
                layer.msg(`操作失败: ${xhr.statusText}`, {icon: 2});
            }
        });
    }

    // 删除车辆信息
    function deleteTruckUnit(data) {
        layer.confirm('确定删除该车辆信息？', {
            icon: 3,
            title: '确认删除'
        }, function(index) {
            $.ajax({
                url: `http://localhost:8080/truck-unit/delete/${data.id}`,
                type: 'DELETE',
                success: function(res) {
                    if (res) {
                        layer.msg('删除成功', {icon: 1});
                        truckUnitTable.reload();
                    } else {
                        layer.msg('删除失败', {icon: 2});
                    }
                },
                error: function(xhr) {
                    console.error('删除失败:', xhr);
                    layer.msg(`删除失败: ${xhr.statusText}`, {icon: 2});
                }
            });
            layer.close(index);
        });
    }

    // 添加单位功能
    $('#addUnitBtn').click(() => addUnit());

    // 添加单位
    function addUnit() {
        layer.open({
            type: 1,
            title: '添加单位',
            area: ['500px', '400px'],
            content: laytpl($('#addUnitTpl').html()).render(),
            success: function(layero) {
                form.render(); // 渲染表单元素

                // 绑定提交事件
                form.on('submit(addUnitForm)', function(formData) {
                    submitUnit(formData, false);
                    return false;
                });
            }
        });
    }

    // 编辑单位
    function editUnit(data) {
        layer.open({
            type: 1,
            title: '编辑单位',
            area: ['500px', '400px'],
            content: laytpl($('#addUnitTpl').html()).render({
                id: data.id,
                unitName: data.unitName
            }),
            success: function(layero) {
                // 填充表单
                form.val("addUnitForm", {
                    id: data.id,
                    unitName: data.unitName
                });

                form.render(); // 重新渲染表单

                // 绑定提交事件
                form.on('submit(addUnitForm)', function(formData) {
                    submitUnit(formData, true, data);
                    return false;
                });
            }
        });
    }

    // 提交单位
    function submitUnit(formData, isEdit, originalData) {
        const fields = formData.field;

        // 如果是编辑，保留原始ID
        if (isEdit) {
            fields.id = originalData.id;
        }

        $.ajax({
            url: isEdit ? 'http://59.110.144.74:8080/unit/update' : 'http://59.110.144.74:8080/unit/add',
            method: isEdit ? 'PUT' : 'POST',
            contentType: 'application/json',
            data: JSON.stringify(fields),
            success: function(res) {
                if (res.success !== undefined && res.success) {
                    layer.msg(isEdit ? '更新成功' : '添加成功', {icon: 1});
                    unitTable.reload();
                    layer.closeAll();
                } else {
                    layer.msg(isEdit ? '更新失败' : '添加失败', {icon: 2});
                }
            },
            error: function(xhr) {
                console.error(isEdit ? '更新失败:' : '添加失败:', xhr);
                layer.msg(`操作失败: ${xhr.responseJSON?.message || xhr.statusText}`, {icon: 2});
            }
        });
    }

    // 删除单位
    function deleteUnit(data) {
        layer.confirm('确定删除该单位？', {
            icon: 3,
            title: '确认删除'
        }, function(index) {
            $.ajax({
                url: `http://localhost:8080/unit/user/delete/${data.id}`,
                type: 'DELETE',
                success: function(res) {
                    if (res.success !== undefined && res.success) {
                        layer.msg('删除成功', {icon: 1});
                        unitTable.reload();
                    } else {
                        layer.msg('删除失败', {icon: 2});
                    }
                },
                error: function(xhr) {
                    console.error('删除失败:', xhr);
                    layer.msg(`删除失败: ${xhr.statusText}`, {icon: 2});
                }
            });
            layer.close(index);
        });
    }

    // 添加门岗功能
    $('#addGateBtn').click(() => addGate());

    // 添加门岗
    function addGate() {
        layer.open({
            type: 1,
            title: '添加门岗',
            area: ['500px', '400px'],
            content: laytpl($('#addGateTpl').html()).render(),
            success: function(layero) {
                form.render(); // 渲染表单元素

                // 绑定提交事件
                form.on('submit(addGateForm)', function(formData) {
                    submitGate(formData, false);
                    return false;
                });
            }
        });
    }

    // 编辑门岗
    function editGate(data) {
        layer.open({
            type: 1,
            title: '编辑门岗',
            area: ['500px', '400px'],
            content: laytpl($('#addGateTpl').html()).render({
                id: data.id,
                gate: data.gate
            }),
            success: function(layero) {
                // 填充表单
                form.val("addGateForm", {
                    id: data.id,
                    gate: data.gate
                });

                form.render(); // 重新渲染表单

                // 绑定提交事件
                form.on('submit(addGateForm)', function(formData) {
                    submitGate(formData, true, data);
                    return false;
                });
            }
        });
    }

    // 提交门岗
    function submitGate(formData, isEdit, originalData) {
        const fields = formData.field;

        // 如果是编辑，保留原始ID
        if (isEdit) {
            fields.id = originalData.id;
        }

        $.ajax({
            url: isEdit ? 'http://59.110.144.74:8080/gate/update' : 'http://59.110.144.74:8080/gate/add',
            method: isEdit ? 'PUT' : 'POST',
            contentType: 'application/json',
            data: JSON.stringify(fields),
            success: function(res) {
                if (res.success !== undefined && res.success) {
                    layer.msg(isEdit ? '更新成功' : '添加成功', {icon: 1});
                    gateTable.reload();
                    layer.closeAll();
                } else {
                    layer.msg(isEdit ? '更新失败' : '添加失败', {icon: 2});
                }
            },
            error: function(xhr) {
                console.error(isEdit ? '更新失败:' : '添加失败:', xhr);
                layer.msg(`操作失败: ${xhr.responseJSON?.message || xhr.statusText}`, {icon: 2});
            }
        });
    }

    // 删除门岗
    function deleteGate(data) {
        layer.confirm('确定删除该门岗？', {
            icon: 3,
            title: '确认删除'
        }, function(index) {
            $.ajax({
                url: `http://localhost:8080/gate/delete/${data.id}`,
                type: 'DELETE',
                success: function(res) {
                    if (res.success !== undefined && res.success) {
                        layer.msg('删除成功', {icon: 1});
                        gateTable.reload();
                    } else {
                        layer.msg('删除失败', {icon: 2});
                    }
                },
                error: function(xhr) {
                    console.error('删除失败:', xhr);
                    layer.msg(`删除失败: ${xhr.statusText}`, {icon: 2});
                }
            });
            layer.close(index);
        });
    }

    // 登出功能
    $('#logoutBtn').click(function () {
        layer.confirm('确定要退出系统吗？', {
            icon: 3,
            title: '确认退出'
        }, function (index) {
            // 清除会话信息
            sessionStorage.removeItem('username');
            sessionStorage.removeItem('unitId');

            // 跳转到登录页面
            window.location.href = '/login.html';
            layer.close(index);
        });
    });
});
